import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // {
  //   path: '/',
  //   component: () => import('@/views/login/index'),
  //   hidden: true
  // },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    name: 'mobile',
    redirect: '/mobile/bannerList',
  },
  {
    path: '/mobile',
    component: Layout,
    name: 'mobile',
    redirect: '/mobile/bannerList',
    meta: { title: '移动端管理', icon: 'app' },
    children: [
      {
        path: 'bannerList',
        name: 'bannerList',
        component: () => import('@/views/bannerList/index'),
        meta: { title: '首页Banner配置',isTab: true},
        children:[]
      },
      {                                       
        path: 'bannerList/addBanner/:id',                //路径及携带参数
        component: () => import('@/views/bannerList/addBanner'),
        name: 'addBanner',
        meta: { title: '新建banner', noCache: true,activeMenu:"/mobile/bannerList",isTab: true },
        hidden: true   //不显示在菜单上
      },
      {
        path: 'floor',
        name: 'floor',
        component: () => import('@/views/floor/index'),
        meta: { title: '首页楼层配置',isTab: true},
        children:[]
      },
    ]
  }, {
    path: '/userManager',
    component: Layout,
    name: 'userManager',
    redirect: '/userManager/index',
    meta: { title: '用户管理', icon: 'userman' },
    children: [
      {
        path: 'userManager',
        name: 'userManager',
        component: () => import('@/views/userManager/index'),
        meta: { title: '用户列表',isTab: true},
        children:[]
      },
      {                                       
        path: 'userManager/userDetail/:id',                //路径及携带参数
        component: () => import('@/views/userManager/userDetail'),
        name: 'userDetail',
        meta: { title: '用户详情', noCache: true,activeMenu:"/userManager/userDetail",isTab: true },
        hidden: true   //不显示在菜单上
      }
    ]
  }, 
  {
    path: '/order',
    component: Layout,
    name: 'order',
    redirect: '/order/orderList',
    meta: { title: '订单管理', icon: 'dingdan' },
    children: [
      {
        path: 'orderList',
        name: 'orderList',
        component: () => import('@/views/order/index'),
        meta: { title: '订单列表',isTab: true},
        children:[]
      },
      {                                       
        path: 'orderList/orderDetail/:id',                //路径及携带参数
        component: () => import('@/views/order/orderDetail'),
        name: 'orderDetail',
        meta: { title: '订单详情', noCache: true,activeMenu:"/order/orderDetail",isTab: true },
        hidden: true   //不显示在菜单上
      }
    ]
  },
  {
    path: '/project',
    component: Layout,
    name: 'project',
    redirect: '/project/projectList',
    meta: { title: '项目管理', icon: 'guanli' },
    children: [
      {
        path: 'projectList',
        name: 'projectList',
        component: () => import('@/views/projectList/index'),
        meta: { title: '项目列表',isTab: true},
        children:[]
      },
      {                                       
        path: 'projectList/addProject/:id',                //路径及携带参数
        component: () => import('@/views/projectList/addProject'),
        name: 'addProject',
        meta: { title: '新建项目', noCache: true,activeMenu:"/project/projectList",isTab: true },
        hidden: true   //不显示在菜单上
      },
      {                                       
        path: 'projectList/detailProject/:id',                //路径及携带参数
        component: () => import('@/views/projectList/detailProject'),
        name: 'detailProject',
        meta: { title: '项目详情', noCache: true,activeMenu:"/project/projectList",isTab: true },
        hidden: true   //不显示在菜单上
      },
      {                                       
        path: 'projectList/map/:id',                //路径及携带参数
        component: () => import('@/views/projectList/map'),
        name: 'map',
        meta: { title: '项目详情', noCache: true,activeMenu:"/project/projectList",isTab: true },
        hidden: true   //不显示在菜单上
      },
      {
        path: 'shopList',
        name: 'shopList',
        component: () => import('@/views/shopList/index'),
        meta: { title: '商品列表',isTab: true }
      },
      {                                       
        path: 'shopList/addShop/:id',                //路径及携带参数
        component: () => import('@/views/shopList/addShop'),
        name: 'addShop',
        meta: { title: '新建商品', noCache: true,activeMenu:"/project/shopList",isTab: true },
        hidden: true   //不显示在菜单上
      },
      {                                       
        path: 'shopList/detailShop/:id',                //路径及携带参数
        component: () => import('@/views/shopList/detailShop'),
        name: 'detailShop',
        meta: { title: '商品详情', noCache: true,activeMenu:"/project/shopList",isTab: true },
        hidden: true   //不显示在菜单上
      },
    ]
  }, {
    path: '/businessManag',
    component: Layout,
    name: 'businessManag',
    redirect: '/businessManag/businessManag',
    meta: { title: '商户管理', icon: 'busess' },
    children: [
      {
        path: 'businessManag',
        name: 'businessManag',
        component: () => import('@/views/businessManag/index'),
        meta: { title: '商户列表',isTab: true},
        children:[]
      },
    ]
  }, 
  // 先去掉分销模块，放在5月份版本
  // {
  //   path: '/salesManager',
  //   component: Layout,
  //   name: 'salesManager',
  //   redirect: '/salesManager/salesManager',
  //   meta: { title: '分销管理', icon: 'fenxiao2' },
  //   children: [
  //     {
  //       path: 'salesManager',
  //       name: 'salesManager',
  //       component: () => import('@/views/salesManager/index'),
  //       meta: { title: '分销员管理',isTab: true},
  //       children:[]
  //     },
  //   ]
  // },

  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
